package com.hzj.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzj.pojo.SmbmsRole;
import com.hzj.pojo.SmbmsUser;
import com.hzj.service.SmbmsRoleService;
import com.hzj.service.SmbmsUserService;
import myWarpper.MyWarpper;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpSession;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hzj
 * @since 2021-04-14
 */
@Controller
public class SmbmsUserController {
    @Reference
    SmbmsUserService sus;
    @Reference
    SmbmsRoleService srs;

    @PostMapping("/login")
    public String login(String userCode, String userPassword, Model model, HttpSession session) {
        SmbmsUser user = new SmbmsUser();
        user.setUsercode(userCode);
        user.setUserpassword(userPassword);
        SmbmsUser one = sus.checkUser(user);
        if (one != null) {
            session.setAttribute("user",one);
            SmbmsRole smbmsRole = srs.getById(one.getId());
            model.addAttribute(smbmsRole);
            return "html/frame";
        } else {
            model.addAttribute("erroe", "账号或密码错误");
            return "login";
        }
    }

    @GetMapping("/test")
    public String test() {
        return "html/billlist";
    }
}

